package cn.itcast.bos.dao.base;

import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.domain.base.FixedArea;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

/**
 * Created by xbqco on 2018/7/12.
 */
public interface CourierRepository extends JpaRepository<Courier,Integer> , JpaSpecificationExecutor<Courier> {

    @Query(value="update Courier set deltag = '0' where id = ?")
    @Modifying
    public void updateDeltag(Integer id);

    @Query(value="update Courier set deltag = '1' where id = ?")
    @Modifying
    public void restore(Integer id);

    public Page<Courier> findByFixedAreasContainingOrderById(Pageable pageable, FixedArea fixedArea);

    public Page<Courier> findByIdNotInOrderById(Pageable pageable, Set<Integer> set);

    @Query("select company,count(company) from Courier group by company")
    public List<Object[]> findCourierGroup();
}
